using SqlSugar;
using SqlInjectionScanner.Config;

namespace SqlInjectionScanner.Core
{
    public class SqlSugarDbContext
    {
        public SqlSugarScope Db { get; }

        public SqlSugarDbContext(DatabaseConfig config)
        {
            Db = new SqlSugarScope(new ConnectionConfig()
            {
                ConnectionString = config.ConnectionString,
                DbType = GetDbType(config.DatabaseType),
                IsAutoCloseConnection = true
            });
        }

        private DbType GetDbType(string databaseType)
        {
            return databaseType switch
            {
                "SqlServer" => DbType.SqlServer,
                "MySql" => DbType.MySql,
                "PostgreSql" => DbType.PostgreSQL,
                "SQLite" => DbType.Sqlite,
                "Oracle" => DbType.Oracle,
                _ => DbType.SqlServer
            };
        }
    }
}